import './detail.css';
import {connect} from 'react-redux';
import {Link} from 'react-router';
import Panel from './../../elements/Panel'
import {URL, setTitle} from '../../libs/Url';
import CONFIG from '../../libs/config';
import {Lang, Fetch} from '../../libs/';
import BreadcrumbNavigation from './../../components/BreadcrumbNavigation';

import {
    fetch,
    fetch_remove,
    enable_delete_btn,
    selectAllItem,
    selectItem,
} from '../../actions';
import {SUBJECT, PAGE_SUBJECT} from './../../actions/subject'
const Title = React.createClass({
    render(){
        return (
            <h1 className="text-center mtop35">{this.props.title}</h1>
        )
    }
});
const Des = React.createClass({
    render(){
        return (
            <p className="text-center auth-row">
                作者： <Link to="#">{this.props.author}</Link> |
                时间：{Moment(this.props.intime).format('YYYY-MM-DD HH:MM:ss')} | 来源：<Link
                to="#">{this.props.source}</Link>
            </p>
        )
    }
})
const Detail = React.createClass({
    getInitialState(){
        return {
            honour: {}
        }
    },
    componentDidMount(){
        setTitle(Lang.title.detail_class_honour);
        const {dispatch} = this.props, self = this;
        Fetch(URL.CLASS_HONOUR_GET, {
            body: {honerid: this.props.params.id}
        })
            .then(res=> {
                console.log(res.honer);
                self.setState({
                    honour_title: res.honer.name,
                    honour_create: res.honer.intime,
                    honour_person: res.honer.intime,
                    honour_file: res.honer.fileids,
                })
            })
            .catch(e=> {
                console.log(e);
            });
        // dispatch(fetch({url: URL.CLASS_HONOUR_GET, honerid: this.props.params.id}));
        // dispatch(fetch(SUBJECT.NEWS_DETAIL, {newsid: this.props.params.id,url:CONFIG.NEWS_PUSH_CLASS}))
    },
    render(){
        const news = (this.props[SUBJECT.CLASS_HONOUR_DETAIL] && this.props[SUBJECT.CLASS_HONOUR_DETAIL].news) ? this.props[SUBJECT.CLASS_HONOUR_DETAIL].news : {};
        
        return (
            <div>
                <BreadcrumbNavigation navs={[
                    {url: CONFIG.MENUS_ABSOLUTE.HOME, label: '首页'},
                    {url: CONFIG.MENUS_ABSOLUTE.CLASS_HONOUR, label: '班級荣誉'},
                    {label: '详情'},
                ]}></BreadcrumbNavigation>

                <Panel>
                    <div className="panel-body">
                        <Title {...news}></Title>
                        <Des {...news}/>
                        <div className="abstract"><b>摘要：</b>
                            {news.summary}
                        </div>
                        <div className="blog-img-wide">
                            <img src={URL.FUN_UPLOAD_PREVIEW(this.state.honour_file)} alt=""/>
                        </div>
                        <div dangerouslySetInnerHTML={{__html: news.content}}></div>
                        <div className="blog-tags">
                            推送到的班级： <span>全部</span><span>一年级1班</span><span>一年级2班</span><span>三年级4班</span>
                        </div>
                    </div>
                </Panel>
            </div>
        )
    }
})
function select(state) {
    return {
        [SUBJECT.CLASS_HONOUR_DETAIL]: state.fetchBySubject[SUBJECT.CLASS_HONOUR_DETAIL],
    }
}
export default connect(select)(Detail)